<template>
	<view style="padding: 30rpx;">
		<view class="flex-center topBox">
			<image :src="merchant.logo"></image>
			<view>{{merchant.name}}</view>
		</view>
		<view class="card">
			<view style="text-align: center;">核销码</view>
			<view class="flex inputBox">
				<view class="flex"></view><input style="text-align: center;" type="text" disabled="disabled" v-model="hxcode" />
			</view>
		</view>
		<view class="submitBtn flex" @click="onImmediatelyHeXiao">立即核销</view>
	</view>
</template>

<script>
	import {
		busHeXiao,
		merchantGoods,
		getPersonalCenter
	} from "@/api/index.js"
	export default {
		data() {
			return {
				opt: {},
				isload: false,
				centerMsg: {},
				merchant: {},
				hxcode: '',
				mid: '',
				hexiaoData: {},
				nodata: false,
				nomore: false
			};
		},
		async onLoad(opt) {
			this.opt = opt
			this.hxcode = opt.hxcode;
			this.mid = opt.mid;
			await this.onGetPersonalCenter();
			this.getdata();
		},
		onShow() {
			this.onGetPersonalCenter()
		},
		onPullDownRefresh() {
			this.getdata();
		},
		methods: {
			async onGetPersonalCenter() {
				const res = await getPersonalCenter('s=/ApiZwyRequest/userinfo')
				const {
					data,
					status,
					msg
				} = res.data
				if (status == 1) {
					this.centerMsg = data
					if (!this.centerMsg.business) {
						this.showToast("请登录商家账号核销")
					} else {
						this.merchant = this.centerMsg.business
						uni.setStorageSync('merchant', this.centerMsg.business)
					}
				} else {
					this.showToast(msg)
				}
			},
			onBakc() {
				setTimeout(() => {
					uni.reLaunch({
						url: '/package/mine/businessCenter'
					})
				}, 2000)
			},
			async onImmediatelyHeXiao() {
				if (!this.merchant) {
					this.showToast("请登录商家账号核销")
					return;
				}
				if (!this.merchant.id) {
					this.showToast("请登录商家账号核销")
					return;
				}
				if (!this.hxcode) {
					this.showToast("核销码不正确")
					return;
				}
				const res = await busHeXiao('s=ApiZwyRequest/submithx', {
					hxcode: this.hxcode,
					bid: this.merchant.id
				})
				const {
					status,
					order,
					msg
				} = res.data
				this.showToast(msg)
				if (status == 1) {
					this.onBakc()
					// console.log(res, "ressss22---")
				}
			},
			// 数据
			async getdata() {
				const res = await busHeXiao('s=ApiZwyRequest/hxbusinessdata', {
					hxcode: this.hxcode,
					mid: this.mid,
					bid: this.merchant.id
				})
				const {
					status,
					data,
					msg
				} = res.data

				if (status == 1) {
					// console.log(res, "res---")
					this.hexiaoData = data
					// this.loaded();
				} else {
					this.showToast(msg)
					// this.onBakc()
				}
			},
		}
	};
</script>
<style lang="less" scoped>
	page {
		font-size: 28rpx;
		background: #f6f6f6
	}


	.submitBtn {
		margin-top: 10vh;
		color: #fff;
		font-size: 34rpx;
		background: #41644A;
		border-radius: 14rpx;
		padding: 20rpx 0;
		justify-content: center;
	}

	.card {
		border-radius: 30rpx;
		font-size: 32rpx;
		background: #fff;
		padding: 30rpx;
		font-weight: 500;
		margin-top: 98rpx;
		margin-bottom: 75rpx;

		.inputBox {
			height: 130rpx;
			border-bottom: 1px solid #F5F5F5;

			view {
				font-size: 40rpx;
				align-items: center;
			}

			input {
				font-weight: bold;
				padding-left: 40rpx;
				font-size: 46rpx;
				height: 130rpx;
				width: 100%;
			}

		}


	}

	.topBox {
		flex-direction: column;
		font-size: 34rpx;
		font-weight: bold;

		image {
			margin-bottom: 36rpx;
			width: 160rpx;
			height: 160rpx;
			border-radius: 15rpx;
		}
	}
</style>